// nmath.cpp : Defines the exported functions for the DLL application.
//

#include "stdafx.h"

PHP_MINIT_FUNCTION(nmath);
PHP_MSHUTDOWN_FUNCTION(nmath);
PHP_RINIT_FUNCTION(nmath);
PHP_RSHUTDOWN_FUNCTION(nmath);
PHP_MINFO_FUNCTION(nmath);

ZEND_FUNCTION(convert_to_prefix);
ZEND_FUNCTION(derivative_to_prefix);

zend_function_entry nmath_functions[] = {
	ZEND_FE(convert_to_prefix, NULL)
	ZEND_FE(derivative_to_prefix, NULL)
	{NULL, NULL, NULL}
};

zend_module_entry nmath_module_entry = {
	STANDARD_MODULE_HEADER,
	"nmath module",
	nmath_functions,
	PHP_MINIT(nmath),
	PHP_MSHUTDOWN(nmath),
	PHP_RINIT(nmath),
	PHP_RSHUTDOWN(nmath),
	PHP_MINFO(nmath),
	NO_VERSION_YET, STANDARD_MODULE_PROPERTIES

};
ZEND_GET_MODULE(nmath)

PHP_MINIT_FUNCTION(nmath){
	return SUCCESS;
}

PHP_MSHUTDOWN_FUNCTION(nmath){
	return SUCCESS;
}

PHP_RINIT_FUNCTION(nmath){
	return SUCCESS;
}

PHP_RSHUTDOWN_FUNCTION(nmath){
	return SUCCESS;
}

PHP_MINFO_FUNCTION(nmath){
	php_info_print_table_start();
	php_info_print_table_header(2, "nmath support", "enabled");
	php_info_print_table_end();
}

ZEND_FUNCTION(convert_to_prefix){
	char *strF;
	char *vars;
	int len, lenvar, error;
	Function f;

	if( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &strF, &len,
		&vars, &lenvar) == FAILURE ){
			return;
	}
	initFunct(&f);
	reset(&f, strF, &error);
	setVariables(&f, vars, lenvar);
	releaseFunct(&f);
	return;
}

ZEND_FUNCTION(derivative_to_prefix){
	char *strF;
	char *vars;
	int len, lenvar, error;
	Function f;

	if( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &strF, &len,
		&vars, &lenvar) == FAILURE ){
			return;
	}
	initFunct(&f);
	reset(&f, strF, &error);
	setVariables(&f, vars, lenvar);

	releaseFunct(&f);
	return;
}